#include <stdio.h>  
int arr[15];  
int ans[15];  
  
int main(void) {  
    for (int i = 0; i < 15; i++)  
        ans[i] = -1;  
    int n, dir;  
    if (scanf("%d%d", &dir, &n)) ;  
    for (int i = 0; i < n; i++)  
        if (scanf("%d", &arr[i])) ;  
    if (dir == 1) {  
        for (int i = 0; i < n; i++) {  
            int cnt = 0;  
            for (int j = i - 1; j >= 0; j--)  
                if (arr[j] < arr[i])  
                    cnt++;  
            if (i == n - 1)  
                printf("%d\n", cnt);  
            else  
                printf("%d ", cnt);  
        }  
    } else {  
        int now = 0;  
        for (int i = 0; i < n; i++) {  
            int cnt = i;  
            for (int j = n - 1; j >= 0; j--) {  
                if (ans[j] == -1 && arr[j] == cnt)  
                    ans[j] = i;  
                if (ans[j] != -1)  
                    cnt--;  
            }  
        }  
        for (int i = 0; i < n; i++)  
            if (i == n - 1)  
                printf("%d\n", ans[i]);  
            else  
                printf("%d ", ans[i]);  
    }  
    return 0;  
}  